package com.qfjy.controller.example5;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName UserController
 * @Description TODO  用户模块
 * @Author guoweixin
 * @Date 2022/4/2
 * @Version 1.0
 */
@Controller
@RequestMapping("user")
@Slf4j
public class UserController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @RequestMapping("register")
    @ResponseBody
    public String registerUser(@RequestParam("uname")String uname,
                               @RequestParam(value = "time",required = false,defaultValue = "3000") int delayTime){

        log.info("用户注册成功--业务逻辑（service/mapper"+uname);

        //int delayTime=5000;
        /** TODO 队列发送 rabbitmq【消息队列】
         *      延迟队列 【5秒】 时间单位ms 毫秒
         *      String exchange 交换机名称（延迟队列交换机）
         *      String routingKey 路由KEY
         *      Object message 数据传输的载体（字符串，如果是对象，将对象转成JSON字符串）
         *      MessagePostProcessor messagePostProcessor   延迟时间是多少  jdk
         *
         */
        amqpTemplate.convertAndSend("delayed.exchange.user.register","delayed.key.user.register",
                uname,message -> {
                    //延迟队列时间  默认 毫米ms
                    message.getMessageProperties().setDelay(delayTime);
                    return message;
                });


        return "用户注册成功";
    }
}
